package net;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;

/**
 * Created with IntelliJ IDEA.
 * User: leep
 * Date: 16-3-1
 * Time: 下午5:13
 * To change this template use File | Settings | File Templates.
 */
public class NetTest {
	public static void main(String[] args) throws Exception {
		String postUrl = "http://116.31.92.201:38080/tpf/order/create.htm/2001340";
		String postData = "token=&_inputCharset=UTF-8&orderNo=&outTradeNo=&orderAmount=&signType=MD5&sign=";
		URL url = new URL(postUrl);
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		conn.setRequestMethod("POST");
		conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
		conn.setRequestProperty("Connection", "Keep-Alive");
		conn.setUseCaches(false);
		conn.setDoOutput(true);

		conn.setRequestProperty("Content-Length", "" + postData.length());
		OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
		out.write(postData);
		out.flush();
		out.close();
		//获取响应状态
		if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
			System.out.println("connect failed!");
		}
		//获取响应内容体
		String line, result = "";
		BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
		while ((line = in.readLine()) != null) {
			result += line + "\n";
		}
		in.close();
		System.out.println(result);
	}
}
